import 'package:flutter/material.dart';

class MyApp3 extends StatefulWidget {
  const MyApp3({super.key});

  @override
  State<MyApp3> createState() => _MyApp3State();
}

class _MyApp3State extends State<MyApp3> {
  //状态变量
  int age = 20;
  final String name = '张三';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //导航条
      appBar: AppBar(
        title: const Text('有状态组件',
            style: TextStyle(
                fontSize: 20,
                fontWeight: FontWeight.bold,
                color: Colors.white)),
        backgroundColor: Colors.pink,
        centerTitle: true,
      ),
      //主题区域
      body: Center(
        child: Text(
          '我叫$name,今年$age岁',
          style: const TextStyle(fontSize: 30),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          //print(age);
          setState(() {
            age = age + 1;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
